﻿
@{
    ViewBag.Title = "选择用户";
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}
@section styles{
    <link rel="stylesheet" href="~/Content/js/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css" />
}
<div id="dMain">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox" style="margin-bottom: 0px;">
            <div class="col-md-5">
                @using (Ajax.BeginForm("_AddUser", "Components", new AjaxOptions() { HttpMethod = "post", OnSuccess = "afterOk" }, new { area = "", id = "datarightfrom", name = "datarightfrom" }))
                {
                    @Html.AntiForgeryToken()
                    <div id="toolbar">
                        <button type="button" class="btn btn-success" id="btn-check-all">全选</button>
                        <button type="button" class="btn btn-danger" id="btn-uncheck-all">全不选</button>
                    </div>
                    <div id="treeview-checkable" class="ztree" style="margin-top:5px;"></div>
                    <input id="Right" type="hidden" value="@ViewBag.right" />
            }
            </div>
            <div class="col-md-7"></div>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/jquery/jquery.unobtrusive-ajax.min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Scripts/MicrosoftAjax.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/zTree/js/jquery.ztree.all-3.5.min.js")"></script>
    <script>
        $("#btn-check-all").click(function () {
            $.fn.zTree.getZTreeObj("treeview-checkable").checkAllNodes(true);
        });
        $("#btn-uncheck-all").click(function () {
            $.fn.zTree.getZTreeObj("treeview-checkable").checkAllNodes(false);
        });
        var callbackiddata = function () {
            var check = $.fn.zTree.getZTreeObj("treeview-checkable").getCheckedNodes(true);
            var idlist = new Array();
            $.each(check, function (i, o) {
                idlist.push(o.id.replace('U',''));
            });
            var idstr = idlist.join(',');
            return idstr;
        }
        var callbacktextdata = function () {
            var check = $.fn.zTree.getZTreeObj("treeview-checkable").getCheckedNodes(true);
            var textlist = new Array();
            $.each(check, function (i, o) {
                textlist.push(o.name);
            });
            var strs = textlist.join(',');
            return strs;
        }


        var zTreeObj;
        // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
        var setting = {
            check: {
                enable: true,
                chkStyle: "checkbox",
                chkboxType: { "Y": "ps", "N": "ps" }
            }
        };
        // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）  

        $.getJSON('@Url.Action("GetjsonZTreeData", "Components", new { area = ""})', { idstr: $('#Right').val() },function (data) {
            if (data != null) {
                zTreeObj = $.fn.zTree.init($("#treeview-checkable"), setting, data);
            }
        });

    </script>
}
